package com.hst.capacity.infra.persistence.jpa.account;

import com.hst.capacity.domain.model.entity.account.SpDriverAccountEntity;
import com.hst.capacity.domain.model.response.account.DriverAccountVO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface SpDriverAccountRepository extends JpaRepository<SpDriverAccountEntity, String> {

    SpDriverAccountEntity findByOwnerId(String ownerId);

    @Query(" SELECT new com.hst.capacity.domain.model.response.account.DriverAccountVO(a,d,dp,f) " +
            " FROM SpDriverAccountEntity a INNER JOIN DriverEntity d on d.idDriver = a.ownerId " +
            " INNER JOIN DriverProfileEntity dp ON d.idDriverProfile = dp.idDriverProfile " +
            " INNER JOIN FranchiseeEntity f on d.idFranchisee = f.idFranchisee " +
            " WHERE d.idFranchisee = :idFranchisee ORDER BY a.balance DESC")
    Page<DriverAccountVO> findByAccountSearchParam(String idFranchisee, PageRequest pageRequest);

}